#pragma once

#include <pthread.h>


//专注做一件事，只封装“对原生pthread_mutex_t的基础上”轻量包装
class Mutex
{
public:
    Mutex(pthread_mutex_t *lock)
        : _lock(lock)
    {
    }

    void Lock()
    {
        pthread_mutex_lock(_lock);
    }

    void Unlock()
    {
        pthread_mutex_unlock(_lock);
    }

    ~Mutex()
    {
    }

private:
    pthread_mutex_t *_lock;
};

//专注解决忘记解锁的问题，利用的是RAII的思想自动构造/析构
class LockGuard
{
public:
    LockGuard(pthread_mutex_t*lock)
        :_mutex(lock)
    {
        _mutex.Lock();
    }
    ~LockGuard()
    {
        _mutex.Unlock();
    }
private:
    Mutex _mutex;
};